package sweezy.swf.converter
{
	import sweezy.swf.structure.RGB;
	import sweezy.swf.structure.RGBA;

	public class ColorConverter
	{

		public static function colorAndAlphaToRgba(color:uint, alpha:Number):RGBA
		{
			var rgba:RGBA = new RGBA();
			rgba.alpha = uint(alpha * 255);
			rgba.red = (color & 0xff0000) >> 16;
			rgba.green = (color & 0xff00) >> 8;
			rgba.blue = color & 0xff;

			return rgba;
		}

		public static function colorToRgb(color:uint):RGB
		{
			var rgb:RGB = new RGB();
			rgb.red = (color & 0xff0000) >> 16;
			rgb.green = (color & 0xff00) >> 8;
			rgb.blue = color & 0xff;

			return rgb;
		}

		public static function colorToRgba(color:uint):RGBA
		{
			var rgba:RGBA = new RGBA();
			rgba.alpha = (color & 0xff000000) >> 24;
			rgba.red = (color & 0xff0000) >> 16;
			rgba.green = (color & 0xff00) >> 8;
			rgba.blue = color & 0xff;

			return rgba;
		}

		public static function rgbToColor(rgb:RGB):uint
		{
			return (rgb.red << 16) || (rgb.green << 8) || rgb.blue;
		}

		public static function rgbaToColor(rgba:RGBA):uint
		{
			return (rgba.alpha << 24) || (rgba.red << 16) || (rgba.green << 8) || rgba.blue;
		}
	}
}